package com.tanhua.server.controller;

import com.tanhua.domain.vo.PageResult;
import com.tanhua.server.service.VideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@Slf4j
@RequestMapping("/smallVideos")
public class VideoController {

    @Autowired
    private VideoService videoService;


    /**
     * 接口名称：小视频列表
     接口路径：GET/smallVideos
     */
    @GetMapping
    public ResponseEntity followUser(@RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer pagesize){
       PageResult pageResult = videoService.queryVideoList(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }


    /**
     *接口名称：视频上传
     * 接口路径：POST/smallVideos
     */
    @PostMapping
    public ResponseEntity uploadVideos(MultipartFile videoThumbnail, MultipartFile videoFile,String text) throws IOException {
        return videoService.uploadVideos(videoThumbnail,videoFile,text);
    }


    /**
     *接口名称：视频用户关注
     *接口路径：POST/smallVideos/:uid/userFocus
     */
    @PostMapping("/{uid}/userFocus")
    public ResponseEntity followUser(@PathVariable("uid") Long followUserId) throws IOException {
        return videoService.followUser(followUserId);
    }


    /**
     *接口名称：视频用户关注 - 取消
     * 接口路径：POST /smallVideos/:uid/userUnFocus
     */
    @PostMapping("/{uid}/userUnFocus")
    public ResponseEntity unFollowUser(@PathVariable("uid") Long followUserId) throws IOException {
        return videoService.unFollowUser(followUserId);
    }

}
